package com.crawler.util.html;


import java.util.Objects;

/**
 * 信息源链接对象，包含链接URL和文本信息
 *
 * @author guor
 * @date 2014年12月15日 上午9:01:31
 */
public class SourceLink implements Comparable<SourceLink> {

    private String url;

    private String text;

    public SourceLink(String url, String text) {
        super();
        this.url = url;
        this.text = text;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @return the text
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        SourceLink that = (SourceLink) o;
        return Objects.equals(url, that.url);
    }

    @Override
    public int hashCode() {
        return url != null ? url.hashCode() : 0;
    }

    @Override
    public int compareTo(SourceLink o) {
        int f = hashCode() - o.hashCode();
        if (f == 0) {
            return f;
        }
        return f > 0 ? 1 : -1;
    }
}
